import 'package:camera/camera.dart';
import 'package:flutter/material.dart';
import 'package:pro_image_editor/core/models/editor_callbacks/pro_image_editor_callbacks.dart';
import 'package:pro_image_editor/core/models/editor_configs/pro_image_editor_configs.dart';
import 'package:pro_image_editor/shared/utils/platform_info.dart';
import 'custom_widgets_example.dart';
import 'example_helper.dart';
import 'vr_phone_capture.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> with ExampleHelperState<MyHomePage> {
  int _counter = 0;

  late final _callbacks = ProImageEditorCallbacks(
    onImageEditingStarted: onImageEditingStarted,
    onImageEditingComplete: onImageEditingComplete,
    onCloseEditor: (editorMode) => onCloseEditor(editorMode: editorMode),
    mainEditorCallbacks: MainEditorCallbacks(
      helperLines: HelperLinesCallbacks(onLineHit: vibrateLineHit),
    ),
  );

  final _configs = ProImageEditorConfigs(
    designMode: platformDesignMode,
  );

  Future<void> _incrementCounter() async {
    final cameras = await availableCameras();
    final firstCamera = cameras.first;
    Navigator.push(
      context,
      MaterialPageRoute(
        builder: (context) => TakePictureScreen(camera: firstCamera,),
      ),
    );
    setState(() {
      _counter++;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text(widget.title),
      ),
      body: Center(

        child: Column(

          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headlineMedium,
            ),
            GestureDetector(
              onTap: () {
                // var iPath = "/data/user/0/com.example.pro_image_editor_demo/cache/CAP9075842141351044981.jpg";
                // var iPath = "/data/user/0/com.example.pro_image_editor_demo/cache/CAP4618956606816799099.jpg";
                // var iPath = '/var/mobile/Containers/Data/Application/87B1A6D4-AE3D-4E84-B269-62F70BD8EAA2/Documents/camera/pictures/CAP_D2B9126C-0BEB-40B2-8D3F-C954F81F676B.jpg';
                var iPath = "/data/user/0/com.example.pro_image_editor_demo/app_flutter/pano/pano_1754983137434.jpeg";
                Navigator.push(
                  context,
                  MaterialPageRoute(
                      builder: (context) => CustomWidgetsExample(filePath: iPath,)
                  ),
                );
              },
              child: Container(
                width: 80,
                height: 40,
                color: Colors.purple,
              ),
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ), // This trailing comma makes auto-formatting nicer for build methods.
    );
  }
}
